const prompts = require("../../constants/prompts");

Component({
  /**
   * 组件的属性列表
   */
  properties: {
    type: {
      type: String,
      value: "general",
      observer: function (newVal) {
        this.updatePromptList(newVal);
      },
    },
  },

  /**
   * 组件的初始数据
   */
  data: {
    prompts: [],
  },

  lifetimes: {
    attached: function () {
      this.updatePromptList(this.properties.type);
    },
  },

  /**
   * 组件的方法列表
   */
  methods: {
    /**
     * 更新提示词列表
     */
    updatePromptList(type) {
      let promptList = [];

      switch (type) {
        case "person":
          promptList = prompts.person;
          break;
        case "anime":
          promptList = prompts.anime;
          break;
        case "general":
        default:
          promptList = prompts.general;
          break;
      }

      this.setData({
        prompts: promptList,
      });
    },

    /**
     * 点击提示词
     */
    handlePromptTap(e) {
      const { prompt } = e.currentTarget.dataset;
      this.triggerEvent("select", { prompt });
    },
  },
});
